package com.evan.webadmin.biz.controller;


import com.evan.common.core.annotation.MyRequestBody;
import com.evan.common.core.object.MyPageData;
import com.evan.common.core.object.MyPageParam;
import com.evan.common.core.object.ResponseResult;
import com.evan.common.core.util.MyModelUtil;
import com.evan.common.core.util.MyPageUtil;
import com.evan.webadmin.biz.dto.*;
import com.evan.webadmin.biz.helper.DictHelper;
import com.evan.webadmin.biz.model.Evluate;
import com.evan.webadmin.biz.service.IEvluateService;
import com.evan.webadmin.biz.vo.EvluateVo;
import com.github.pagehelper.Page;
import com.github.pagehelper.page.PageMethod;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;

import org.springframework.web.bind.annotation.RestController;

import javax.servlet.http.HttpServletRequest;
import java.util.List;

/**
 * <p>
 *  前端控制器
 * </p>
 *
 * @author Pavel
 * @since 2024-06-15
 */
@RestController
@RequestMapping("/admin/biz/evluate")
public class EvluateController {

    @Autowired
    IEvluateService evluateService;
    @Autowired
    DictHelper dictHelper;

    @PostMapping("/findByCondition")
    public ResponseResult<MyPageData<EvluateVo>> findByCondition(@MyRequestBody EvluateFilter evluateFilter,
                                                              @MyRequestBody MyPageParam pageParam) {
        if (pageParam != null) {
            PageMethod.startPage(pageParam.getPageNum(), pageParam.getPageSize());
        }
        List<Evluate> evluates = evluateService.findByCondition(evluateFilter);
        long totalCount = 0L;
        if (evluates instanceof Page) {
            totalCount = ((Page<Evluate>) evluates).getTotal();
        }
        List<EvluateVo> evluateVos = MyModelUtil.copyCollectionTo(evluates, EvluateVo.class);;
        return ResponseResult.success(MyPageUtil.makeResponseData(evluateVos, totalCount));
    }

    @PostMapping("/record")
    public ResponseResult<Evluate> record(@RequestBody EvluateRecordDto frontDto, HttpServletRequest request) {
        return evluateService.record(frontDto, request);
    }

    @PostMapping("/exist")
    public ResponseResult<EvluateRecordDto> exist(@RequestBody EvluateDtoFilter filter, HttpServletRequest request) {
        return evluateService.exist(filter, request);
    }
}

